package cn.edu.ecjtu.android_tutorials;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class Editpage extends AppCompatActivity {
     TextView name;
     TextView tel ;
     Button button1;
     Button button2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_editpage);
         final Intent intent=getIntent();
        //oldString中间变量按照原来联系人名字修改信息
//        oldString=intent.getStringExtra("name");
         name= (TextView)findViewById(R.id.name);
        tel= (TextView)findViewById(R.id.phone);
        name.setText(intent.getStringExtra("name"));
        tel.setText(intent.getStringExtra("phone"));
         button1= (Button) findViewById(R.id.btn_edit);
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                intent.putExtra("data_return", "Hello SecondActivity");
//                setResult(RESULT_OK, intent);
//                Intent intent=getIntent();
                intent.setClass(Editpage.this, SecondPage.class);
                startActivityForResult(intent,1);

            }


        });
         button2 = (Button) findViewById(R.id.btn_cancel);
        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();

            }


        });
    }

    public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (resultCode) {
            case RESULT_OK:
                if(resultCode==RESULT_OK){
//                    String returnData = data.getStringExtra("data_return");
//                    Log.d("FirstActivity","returnData");
                    String pos=data.getStringExtra("pos");
//                    System.out.println("pos"+pos);
                    Log.d("pos",pos);
//                   name.setText(data.getStringExtra("name"));
//                   tel.setText(data.getStringExtra("phone"));
                    Intent intent = new Intent();
                    intent.putExtra("name", data.getStringExtra("name"));
                    intent.putExtra("phone", data.getStringExtra("phone"));
                    intent.putExtra("pos", data.getStringExtra("pos"));
                    setResult(RESULT_OK,intent);
                    finish();
                }
                break;

        }
    }

}